/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author 
 */
public class Penerimaan {
    private String kodePenerimaan;
    private String waktuPenerimaan;
    private double jumlahBarang;
    private double hargaBarang;
    private String idBarang;
    private String username;
//            String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//    String userid = "hr"; // gantikan dengan username anda
//    String pass = "hr"; // gantikan dengan password anda
    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "mhs115314034"; // gantikan dengan username anda
    String pass = "mhs115314034"; // gantikan dengan password anda

    /**
     * @return the kodePenerimaan
     */
    public String getKodePenerimaan() {
//       try {
//            Connection connection = null;
//            OracleDataSource ds;
//            ds = new OracleDataSource();
//            ds.setURL(jdbcUrl);
//            ds.setPassword(pass);
//            ds.setUser(userid);
//            connection = (Connection) ds.getConnection();
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery("select kodepenerimaan from penerimaanbarang order by kodepenerimaan");
//            String kode_penerimaan = "";
//            Date now = new Date();
//            SimpleDateFormat dateFormatterTanggal = new SimpleDateFormat("d");
//            SimpleDateFormat dateFormatterBulan = new SimpleDateFormat("M");
//            SimpleDateFormat dateFormatterTahun = new SimpleDateFormat("y");
//            String tanggal = dateFormatterTanggal.format(now);
//            String bulan = dateFormatterBulan.format(now);
//            String tahun = dateFormatterTahun.format(now);
//            String substring = tahun.substring(2);
//            String kodeTanggal = tanggal+bulan+substring;
//            while (resultSet.next()) {
//                kode_penerimaan = resultSet.getString("kodepenerimaan");
//            }
//            int no_penerimaan = 0;
//            if ("".equals(kode_penerimaan)) {
//                this.kodePenerimaan = kodeTanggal + "001";
//            } else {
//                String data = kode_penerimaan.substring(0, 6);
//                if (kodeTanggal.equals(data)) {
//                    no_penerimaan = Integer.parseInt(kode_penerimaan) + 1;
//                    this.kodePenerimaan = String.valueOf(no_penerimaan);
//                } else {
//                    this.kodePenerimaan = kodeTanggal + "001";
//                }
//            }
//        } catch (SQLException e) {
//// perform error handling here
//            System.out.println("error :" + e.getMessage());
//            this.kodePenerimaan = null;
//        }
        return kodePenerimaan;
    }
    
    /**
     * @return the waktuPenerimaan
     */
    public String getWaktuPenerimaan() {
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d-M-y");
//        this.waktuPenerimaan = simpleDateFormat.format(date);
        return waktuPenerimaan;
    }

    /**
     * @return the jumlahBarang
     */
    public double getJumlahBarang() {
        return jumlahBarang;
    }

    /**
     * @param jumlahBarang the jumlahBarang to set
     */
    public void setJumlahBarang(double jumlahBarang) {
        this.jumlahBarang = jumlahBarang;
    }

    /**
     * @return the hargaBarang
     */
    public double getHargaBarang() {
        return hargaBarang;
    }

    /**
     * @param hargaBarang the hargaBarang to set
     */
    public void setHargaBarang(double hargaBarang) {
        this.hargaBarang = hargaBarang;
    }

    /**
     * @return the idBarang
     */
    public String getIdBarang() {
        return idBarang;
    }

    /**
     * @param idBarang the idBarang to set
     */
    public void setIdBarang(String idBarang) {
        this.idBarang = idBarang;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
    
//    public String konversiBulanTerima(String bulan){
//        if("Januari".equals(bulan)){
//            return "1";
//        } else if("Februari".equals(bulan)){
//            return "2";
//        } else if("Maret".equals(bulan)){
//            return "3";
//        } else if("April".equals(bulan)){
//            return "4";
//        } else if("Mei".equals(bulan)){
//            return "5";
//        } else if("Juni".equals(bulan)){
//            return "6";
//        } else if("Juli".equals(bulan)){
//            return "7";
//        } else if("Agustus".equals(bulan)){
//            return "8";
//        } else if("September".equals(bulan)){
//            return "9";
//        } else if("Oktober".equals(bulan)){
//            return "10";
//        } else if("November".equals(bulan)){
//            return "11";
//        } else if("Desember".equals(bulan)){
//            return "12";
//        } else {
//            return "0";
//        }
//    }
    
//    public void insertPenerimaan() {
//        try {
//            Connection connection = null;
//            OracleDataSource ds;
//            ds = new OracleDataSource();
//            ds.setURL(jdbcUrl);
//            ds.setPassword(pass);
//            ds.setUser(userid);
//            connection = (Connection) ds.getConnection();
//            Statement statement = connection.createStatement();
//            statement.executeQuery("insert into penerimaanbarang values ('"
//                    + getKodePenerimaan() + "','"
//                    + getWaktuPenerimaan() + "',"
//                    + getJumlahBarang() + ","
//                    + getHargaBarang() + ",'"
//                    + getIdBarang() + "','"
//                    + getUsername() + "')");
//            BarangGudang barangGudang = new BarangGudang();
//            barangGudang.setIdBarang(getIdBarang());
//            barangGudang.setJumlahBarang(getJumlahBarang());
//            barangGudang.setHargaBarang(getHargaBarang());
//            barangGudang.tambahBarang(barangGudang);
//            barangGudang.updateHargaBarangGudang(barangGudang);
//        } catch (SQLException e) {
//// perform error handling here
//            System.out.println("error :" + e.getMessage());
//        }
//    }
    public ResultSet tampilBarang() {
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(pass);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select * from pemesananbarang");
            String hasil[] = null;
            int counter = 0;
            return resultSet;
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return null;
        }
    }
}
